package com.sky.wsp.drools.controller;

import com.sky.wsp.drools.service.AsyncUserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * @desccription 在此输入描述
 * @auth wangshaopeng@talkweb.com.cn
 * @date 2022/5/7
 */
@RestController
@RequestMapping("user")
public class AsyncUserController {
    @Resource
    AsyncUserService asyncUserService;

    @RequestMapping("async")
    public String async() throws InterruptedException, ExecutionException {
        long star = System.currentTimeMillis();
        System.out.println("async开始：" + star);
        Future<String> a = asyncUserService.execTaskA();
        System.out.println("------------------------------1 ：" + System.currentTimeMillis());
        Future<String> b = asyncUserService.execTaskB();
        System.out.println("------------------------------2 ：" + System.currentTimeMillis());
        Future<String> c = asyncUserService.execTaskC();
        System.out.println("do my own task~~~");
        System.out.println("do my own task~~~");
        System.out.println("do my own task~~~");
        System.out.println("do my own task~~~");
        System.out.println("do my own task~~~");
        System.out.println("do my own task~~~");
        System.out.println("do my own task~~~");
        System.out.println("------------------------------3 ：" + System.currentTimeMillis());
        String sa = a.get();
        System.out.println("do my own task2~~~");
        System.out.println("do my own task2~~~");
        System.out.println("do my own task2~~~");
        System.out.println("do my own task2~~~");
        System.out.println("do my own task2~~~");
        System.out.println("do my own task2~~~");
        System.out.println("do my own task2~~~");
        System.out.println("------------------------------4 ：" + System.currentTimeMillis());
        String sb = b.get();
        System.out.println("------------------------------5 ：" + System.currentTimeMillis());
        String sc = c.get();
        System.out.println("------------------------------6 ：" + System.currentTimeMillis());
        System.out.println("共计耗时：" + (star - System.currentTimeMillis()));
        return "OK" + "-" + sa + "-" + sb + "-" + sc ;
    }
}
